package com.boding.power.controller;

import com.belerweb.social.bean.Result;
import com.belerweb.social.qq.connect.api.OAuth2;
import com.belerweb.social.qq.connect.api.QQConnect;
import com.belerweb.social.qq.connect.api.User;
import com.belerweb.social.qq.connect.bean.AccessToken;
import com.belerweb.social.qq.connect.bean.OpenID;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;

public class PhoneController extends Controller {
	// 登录
	@ActionKey("/callback")
	public void callback() {
		String code = getPara("code");
		String clientId = PropKit.get("clientId");
		String clientSecret = PropKit.get("clientSecret");
		String redirect = PropKit.get("redirect");
		QQConnect qqConnect = new QQConnect(clientId, clientSecret, redirect);
		OAuth2 auth2 = qqConnect.getOAuth2();
		Result<AccessToken> result = auth2.accessToken(code);
		String accessToken = result.getResult().getToken();
		Result<OpenID> result2 = auth2.openId(accessToken);
		String openid = result2.getResult().getOpenId();
		// TODO 根据openID 查询数据库商家信息
		// 如果为空则注册商户
		// 不为空显示商户信息
	}
}
